package app.fugema.shop.main.goods.adapter;

import android.view.View;
import android.view.ViewGroup;

import com.base.common.utils.DensityUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.MyLinearLayoutManager;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.imageView.ImageLoaderUtils;
import app.fugema.shop.R;
import app.fugema.shop.databinding.GroupBookingHeadImageItemBinding;
import app.fugema.shop.databinding.GroupBookingItemBinding;
import app.fugema.shop.main.goods.view.GoodsDetailActivity;
import app.fugema.shop.main.order.model.GroupBookingBean;


public class GroupBookingItemMultiType extends BaseItemMultiType<GroupBookingBean.RecordsBean, GroupBookingItemBinding> {
    @Override
    public int getLayoutId() {
        return R.layout.group_booking_item;
    }

    @Override
    public boolean isFullSpanType() {
        return true;
    }

    @Override
    public void onCreateViewHolder(GroupBookingItemBinding binding, BaseViewHolder viewHolder) {
        super.onCreateViewHolder(binding, viewHolder);

        binding.rvRecyclerView.setLayoutManager(new MyLinearLayoutManager(viewHolder.itemView.getContext(), 0, false));
        binding.rvRecyclerView.setAdapter(new SingleRecyclerAdapter<String, GroupBookingHeadImageItemBinding>() {
            @Override
            public int getLayoutId() {
                return R.layout.group_booking_head_image_item;
            }

            @Override
            public void onBindViewHolder(GroupBookingHeadImageItemBinding binding, int position, String bean) {
                super.onBindViewHolder(binding, position, bean);
                ImageLoaderUtils.loadImage(binding.givHeadImage, bean);
                if (binding.givHeadImage.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.givHeadImage.getLayoutParams();
                    if (position == 0) {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_0);
                    } else {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_f10);
                    }
                    binding.givHeadImage.setLayoutParams(marginLayoutParams);
                }

            }
        });
    }


    @Override
    public void onBindViewHolder(GroupBookingItemBinding binding, int position, BaseViewHolder viewHolder, GroupBookingBean.RecordsBean bean) {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        binding.pbProgress.setMax(bean.getDiscountMember());
        binding.pbProgress.setProgress(bean.getJoinEdCount());
        if (viewHolder.getAdapter() != null) {

//            if (binding.clItemView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
//                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.clItemView.getLayoutParams();
//                if (position >= viewHolder.getAdapter().getLastPosition() || viewHolder.getAdapter().getItemViewType(position + 1) == TYPE_CHILD_ONE) {
//                    marginLayoutParams.bottomMargin = DensityUtil.getDimens(R.dimen.dp_12);
//                    binding.clItemView.getDelegate().setCornerRadius_BL(DensityUtil.getDimens(R.dimen.dp_16));
//                    binding.clItemView.getDelegate().setCornerRadius_BR(DensityUtil.getDimens(R.dimen.dp_16));
//                } else {
//                    marginLayoutParams.bottomMargin = DensityUtil.getDimens(R.dimen.dp_0);
//                    binding.clItemView.getDelegate().setCornerRadius_BL(DensityUtil.getDimens(R.dimen.dp_0));
//                    binding.clItemView.getDelegate().setCornerRadius_BR(DensityUtil.getDimens(R.dimen.dp_0));
//                }
//                binding.clItemView.setLayoutParams(marginLayoutParams);
//            }
        }


        if (binding.rvRecyclerView.getAdapter() instanceof BaseRVAdapter) {
            BaseRVAdapter rvAdapter = (BaseRVAdapter) binding.rvRecyclerView.getAdapter();
            if (UIUtils.isNotEmpty(bean.getPics())) {
                rvAdapter.setDataList(bean.getPics());
            } else {
                rvAdapter.clear();
            }

        }
    }

    @Override
    public void onItemClick(View view, int onclickType, int position, GroupBookingBean.RecordsBean bean) {
        super.onItemClick(view, onclickType, position, bean);
        GoodsDetailActivity.start(view.getContext(), bean);
    }
}